var baseurl = "http://localhost:8080";
var public_baseurl = "http://47.98.39.209:8080";
var isLocal = false;

function ajax(url,data,callback,nojson,error){
    var req = new XMLHttpRequest();
    req.open("post",isLocal?baseurl+url:
    public_baseurl+url);
    if(localStorage.token) {
        req.setRequestHeader("token", localStorage.token);
    }
    req.setRequestHeader("content-Type",
        "application/json;charset=utf-8");
    if(!data) data = {}
    req.send(JSON.stringify(data));
    req.onreadystatechange = function(){
        if(req.readyState==4&&req.status==200){
            if(nojson){
                callback(req.responseText);
            }else{
                callback(JSON.parse(req.responseText));
            }
        }else{
            if(error)
                error(req.responseText)
        }
    }
}
